/* global XMLHttpRequest */
'use strict'
import EventEmitter from './EventEmitter'
export default class Http extends EventEmitter {
  get (url) {
    let self = this
    let xhr = new XMLHttpRequest()
    xhr.open('GET', url)
    xhr.onreadystatechange = function () {
      if (xhr.readyState === 4 && xhr.status === 200) {
        self.emit('data', JSON.parse(xhr.responseText))
      }
    }
    xhr.onerror = function () {
      self.emit('error', null)
    }
    xhr.send()
  }
}
